using System;
using System.Collections.Generic;
using System.Text;
using TNI;
using System.Drawing;

namespace Graphics.Films
{
    public class FilmColorAna : Film
    {

        public FilmColorAna(Film.TYPE type, int width, int height)
            : base(type, width, height)
        {
            //m_buffer = new Color[width*height]; 
            //m_currentPos = m_buffer; 

            //GFLC_LIBRARY::initialise(); 
        }


        public override void Trace(TNI.Color c)
        {
            //    *m_currentPos++ = c;
            colors.Add(c);
        }
        public override void Trace(int x, int y, TNI.Color c)
        {
            //m_buffer[x + y * m_width] = c; 
        }
        bool Save(string filename, int format)
        {
            return true;
        }
        bool Save(string filename, string format_name)
        {
            return true;
        }


        public Bitmap GetImage()
        {
            Bitmap image = new Bitmap(m_width, m_height);
            for (int y = 0; y < m_width - 1; y++)
            {
                for (int x = 0; x < m_width && y < m_height; x++)
                {
                    int index = (y * m_width) + x;
                    if (colors.Count > index)
                    {
                        if (index == 1335)
                        {

                        }
                        double r = colors[index].R;
                        double g = colors[index].G;
                        double b = colors[index].B;

                        r *= 255;
                        g *= 255;
                        b *= 255;

                        int R = Convert.ToInt32(r);
                        int G = Convert.ToInt32(g);
                        int B = Convert.ToInt32(b);

                        //int r = (int)colors[index].R;
                        //int g = (int)colors[index].G;
                        //int b = (int)colors[index].B;

                        System.Drawing.Color color = System.Drawing.Color.FromArgb(R, G, B);
                        image.SetPixel(x, y, color);
                    }
                }
            }
            return image;
        }


        private TNI.Color m_buffer, m_currentPos;

    }
}